package com.yj.daily.stream;

import java.util.ArrayList;
import java.util.List;
import java.util.OptionalInt;

/**
 * Stream reduce()使用
 */
public class Demo01 {
    private static List<Person> javaProgrammers;
    static {
       javaProgrammers = new ArrayList<Person>() {
            {
                add(new Person("Elsdon", "Jaycob", "Java programmer", "male", 2000, 18));
                add(new Person("Tamsen", "Brittany", "Java programmer", "female", 2371, 55));
                add(new Person("Floyd", "Donny", "Java programmer", "male", 3322, 25));
                add(new Person("Sindy", "Jonie", "Java programmer", "female", 35020, 15));
                add(new Person("Vere", "Hervey", "Java programmer", "male", 2272, 25));
                add(new Person("Maude", "Jaimie", "Java programmer", "female", 2057, 87));
                add(new Person("Shawn", "Randall", "Java programmer", "male", 3120, 99));
                add(new Person("Jayden", "Corrina", "Java programmer", "female", 345, 25));
                add(new Person("Palmer", "Dene", "Java programmer", "male", 3375, 14));
                add(new Person("Addison", "Pam", "Java programmer", "female", 3426, 20));
            }
        };
    }


    public static void main(String[] args) {

        // 1.求薪资结果
        int salary = javaProgrammers.stream().mapToInt(Person::getSalary).reduce((x, y) -> {

            return x += y;
        }).getAsInt();
        System.out.println(salary);

        salary = javaProgrammers.stream().mapToInt(Person::getSalary).reduce(100,(x, y) -> {

            return x += y;
        });
        System.out.println(salary);
    }
}

class Person{

    private String firstName;
    private String lastName;
    private String work;
    private String sex;
    private int salary;
    private int age;

    public Person(){}

    public Person(String firstName,String lastName,String work,String sex,int salary,int age){
        this.firstName = firstName;
        this.lastName = lastName;
        this.work = work;
        this.sex = sex;
        this.salary = salary;
        this.age = age;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getWork() {
        return work;
    }

    public void setWork(String work) {
        this.work = work;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getSalary() {
        return salary;
    }

    public void setSalary(int salary) {
        this.salary = salary;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}
